import sys
import os
import os.path
import shutil
import json

from jinja2 import Environment, PackageLoader, Template, FileSystemLoader

import mdf.debug as debug
import mdf.config as config
import mdf.utils as utils

loader = FileSystemLoader( config.default_template_dir )
env = Environment( loader = loader )


class Book:
	def __init__( self, name, descr, url, mime ):
		self.name = name
		self.descr = descr
		self.url = url
		self.mime = mime

class Library:
	def __init__( self, filename, datafile ):
		self.filename = filename
		self.datafile = datafile
	
	def render( self ):
		js_f = open( self.datafile )
		js_cfg = json.loads( js_f.read() )
		
		templ = env.get_template("library.thtml")
		f = open( self.filename, "w" )
		f.write( templ.render( library = js_cfg["library"]) )
		f.close()
